//
// Created by 11510 on 2024/6/11.
//
#include <iostream>
#include <math.h>
using namespace std;

class Line;

class Point{
private:
    int _ix;
    int _iy;

public:
    Point(int x = 0, int y = 0): _ix(x), _iy(y){}
//    友元类的声明
    friend class Line;

    void getZ(const Line& rhs);

};


class Line{
public:
//    友元的成员函数形式，使用较多
    float distance(const Point & lhs, const Point & rhs){
        return sqrt(pow(lhs._iy - rhs._iy, 2) + pow(lhs._ix - rhs._ix, 2));
    }

    void setX(Point &lhs, int x){
        lhs._ix = x;
    }
    friend class Point;
private:
    int _iz = 10;
};



void Point::getZ(const Line &rhs) {
    /**
     * point 把 line当友元，但是line不一定把point当友元
     */
    cout << rhs._iz;
}


void test0(){
    Point pt1(0, 0);
    Point pt2(1, 4);
    Line line;
    line.setX(pt2, 3);
    cout << line.distance(pt1, pt2);
}



int main() {
    test0();
    return 0;
}